const fs = require('fs');
const path = require('path');

// 读取.env文件
const envPath = path.resolve(__dirname, '../.env');
const envConfig = {};

if (fs.existsSync(envPath)) {
  const envContent = fs.readFileSync(envPath, 'utf-8');
  envContent.split('\n').forEach(line => {
    line = line.trim();
    if (line && !line.startsWith('#')) {
      const [key, ...valueParts] = line.split('=');
      if (key && valueParts.length > 0) {
        const value = valueParts.join('=').trim();
        envConfig[key.trim()] = value;
      }
    }
  });
}

module.exports = {
  apps: [
    {
      name: 'devtools-backend',
      script: 'dist/main.js',
      cwd: '/www/devtools-hub/backend',
      instances: 1,
      autorestart: true,
      watch: false,
      max_memory_restart: '500M',
      env: {
        NODE_ENV: 'production',
        PORT: 4002,
        ...envConfig
      },
      error_file: './logs/error.log',
      out_file: './logs/out.log',
      log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
      merge_logs: true,
    }
  ]
};


